"""Controller for current agreements."""

from mnemoply.controllers.lookup import TableLookupDataSource
from mnemoply.controllers.StudentAgreement import AgreementController

class CurrentAgreementDataSource(TableLookupDataSource):
    """
        Provides `student_agreement_lookup` with filtration by current year.
    """

    def __init__(self):
        TableLookupDataSource.__init__(self, 'student_agreement_lookup')

    def _buildWhereChunks(self, request):
        chunks = TableLookupDataSource._buildWhereChunks(self, request)
        chunks.append("(NOT ISNULL(group_title) OR ISNULL(date_cancellation_agreement))")  # see schema-addon/views.sql
        return chunks

class CurrentStudentAgreementController(AgreementController):
    """Controller for current agreements."""

    def __init__(self):
        AgreementController.__init__(self, data_source=CurrentAgreementDataSource())
        self.title = _("Current agreement")

exposed = CurrentStudentAgreementController()
